package com.haiyi.software.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;

public class ActivityModifySex extends Activity implements OnClickListener {

	CheckBox ck_sex_male, ck_sex_female, ck_sex_1, ck_sex_0, ck_sex_05,
			ck_sex_t, ck_sex_p, ck_sex_h, ck_sex_tc, ck_sex_bi;

	CheckBox boxs[] = new CheckBox[10];

	private Button btn_saveback;

	private String usex;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_modify_sex);

		getParameters();

		initComp();

		initData();
	}

	private void initData() {
		// TODO 自动生成的方法存根
		for (CheckBox ck : boxs) {
			if (ck.getTag().toString().equals(this.usex)) {
				onClick(ck);
			}
		}
	}

	private void getParameters() {
		// TODO 自动生成的方法存根
		this.usex = this.getIntent().getStringExtra("usex");
	}

	public void initComp() {

		this.btn_saveback = (Button) this.findViewById(R.id.btn_saveback);
		ck_sex_0 = (CheckBox) this.findViewById(R.id.ck_sex_0);
		ck_sex_05 = (CheckBox) this.findViewById(R.id.ck_sex_05);
		ck_sex_1 = (CheckBox) this.findViewById(R.id.ck_sex_1);
		ck_sex_female = (CheckBox) this.findViewById(R.id.ck_sex_female);
		ck_sex_h = (CheckBox) this.findViewById(R.id.ck_sex_h);
		ck_sex_male = (CheckBox) this.findViewById(R.id.ck_sex_male);
		ck_sex_p = (CheckBox) this.findViewById(R.id.ck_sex_p);
		ck_sex_t = (CheckBox) this.findViewById(R.id.ck_sex_t);
		ck_sex_bi = (CheckBox) this.findViewById(R.id.ck_sex_bi);
		ck_sex_tc = (CheckBox) this.findViewById(R.id.ck_sex_tc);

		ck_sex_male.setTag("1");
		ck_sex_female.setTag("2");
		ck_sex_1.setTag("3");
		ck_sex_0.setTag("4");
		ck_sex_05.setTag("5");
		ck_sex_t.setTag("6");
		ck_sex_p.setTag("7");
		ck_sex_h.setTag("8");
		ck_sex_tc.setTag("9");
		ck_sex_bi.setTag("10");

		boxs[0] = ck_sex_male;
		boxs[1] = ck_sex_female;
		boxs[2] = ck_sex_1;
		boxs[3] = ck_sex_0;
		boxs[4] = ck_sex_05;
		boxs[5] = ck_sex_t;
		boxs[6] = ck_sex_p;
		boxs[7] = ck_sex_h;
		boxs[8] = ck_sex_tc;
		boxs[9] = ck_sex_bi;

		ck_sex_0.setOnClickListener(this);
		ck_sex_05.setOnClickListener(this);
		ck_sex_1.setOnClickListener(this);
		ck_sex_female.setOnClickListener(this);
		ck_sex_h.setOnClickListener(this);
		ck_sex_male.setOnClickListener(this);
		ck_sex_p.setOnClickListener(this);
		ck_sex_t.setOnClickListener(this);
		ck_sex_bi.setOnClickListener(this);
		ck_sex_tc.setOnClickListener(this);

		this.btn_saveback.setOnClickListener(saveClick);
	}

	private OnClickListener saveClick = new OnClickListener() {

		@Override
		public void onClick(View v) {

			Intent intent = new Intent();

			intent.putExtra("usex", getCheckedSex());

			setResult(ActivityModifyInformation.SHOW_SUB_ACTIVITY_USEX, intent);

			ActivityModifySex.this.finish();
		}
	};

	@Override
	public void onClick(View v) {

		// TODO 自动生成的方法存根
		ck_sex_0.setChecked(false);
		ck_sex_05.setChecked(false);
		ck_sex_1.setChecked(false);
		ck_sex_female.setChecked(false);
		ck_sex_h.setChecked(false);
		ck_sex_male.setChecked(false);
		ck_sex_p.setChecked(false);
		ck_sex_bi.setChecked(false);
		ck_sex_t.setChecked(false);
		ck_sex_tc.setChecked(false);

		((CheckBox) v).setChecked(true);

	}

	private String getCheckedSex() {

		for (CheckBox cBox : boxs) {

			if (cBox.isChecked()) {

				return (String) cBox.getTag();
			}
		}
		return "";
		// TODO 自动生成的方法存根

	}
}
